package com.gis.visualization.controller.index;

import cn.hutool.core.lang.Console;
import com.gis.visualization.config.result.R;
import com.gis.visualization.entity.vo.TimeCityVo;
import com.gis.visualization.service.HistoryFigureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@RestController
@RequestMapping("/visualization/index")
@Api(tags = "前台显示所需数据")
public class EchartsController {
    @Autowired
    HistoryFigureService figureService;

    @ApiOperation("模糊查询人名")
    @GetMapping("fuzzySearch/{n}")
    public R addFigureLocation(@PathVariable String n) {
        List<Map<String, Object>> names = figureService.getFuzzyNames(n);
        return R.ok().data("names",names);
    }

    @ApiOperation("获取姓氏数据")
    @GetMapping("nameWordCloud")
    public R getLastNames() {
        Map<String, Integer> list = figureService.getNames();
        return R.ok().data("list",list);
    }

    @ApiOperation("在时间和城市的条件下，获取姓氏数据")
    @PostMapping("nameWordCloudByTimeCity")
    public R nameWordCloudByTimeCity(@RequestBody TimeCityVo timeCityVo) {
        Map<String, Integer> list = figureService.nameWordCloudByTimeCity(timeCityVo);
        return R.ok().data("list",list);
    }

    @ApiOperation("获取姓氏词图")
    @GetMapping("getNameWordCloudImg")
    @Cacheable(value = "WordCloudImg",key = "'selectImg'")
    public R getNameWordCloudImg() {
        Map<String, Integer> list = figureService.getNames();
        String url = figureService.getNameWordCloudImg(list);
        return R.ok().data("url",url);
    }

    @ApiOperation("获取年龄分布")
    @GetMapping("getAgeDistribution")
    @Cacheable(value = "age",key = "'distribution'")
    public R getAgeDistribution() {
        List<Map<String, Object>> ageDistribution = figureService.getAgeDistribution();
        return R.ok().data("ageDistribution",ageDistribution);
    }

    @ApiOperation("在时间和城市的条件下，获取年龄分布")
    @PostMapping("getAgeDistributionByTimeCity")
    public R getAgeDistributionByTimeCity(@RequestBody TimeCityVo timeCityVo) {
        List<Map<String, Object>> ageDistribution = figureService.getAgeDistributionByTimeCity(timeCityVo);
        return R.ok().data("ageDistribution",ageDistribution);
    }

    @ApiOperation("获取人物所属城市")
    @GetMapping("getFigureCity")
    @Cacheable(value = "figure",key = "'city'")
    public R getFigureCity() {
        List<TreeMap<String, Object>> figureCity = figureService.getFigureCity();
        return R.ok().data("figureCity",figureCity);
    }

    @ApiOperation("在时间条件下，获取人物所属城市")
    @PostMapping("getFigureCityByTime")
    public R getFigureCityByTime(@RequestBody TimeCityVo timeCityVo) {
        List<TreeMap<String, Object>> figureCity = figureService.getFigureCityByTime(timeCityVo);
        return R.ok().data("figureCity",figureCity);
    }

    @ApiOperation("获取人物性别比例")
    @GetMapping("getSexRatio")
    @Cacheable(value = "sex",key = "'ratio'")
    public R getSexRatio() {
        List<Map<String,Object>> sexRatio = figureService.getSexRatio();
        return R.ok().data("sexRatio",sexRatio);
    }

    @ApiOperation("在时间和城市条件下，获取人物性别比例")
    @PostMapping("getSexRatioByTimeCity")
    public R getSexRatioByTimeCity(@RequestBody TimeCityVo timeCityVo) {
        System.out.println(timeCityVo);
        List<Map<String,Object>> sexRatio = figureService.getSexRatioByTimeCity(timeCityVo);
        return R.ok().data("sexRatio",sexRatio);
    }

    @ApiOperation("获取人物的类型")
    @GetMapping("getFigureTypes")
    @Cacheable(value = "figure",key = "'types'")
    public R getFigureTypes() {
        List<Map<String,Object>> figureTypes = figureService.getFigureTypes();
        return R.ok().data("figureTypes",figureTypes);
    }

    @ApiOperation("在时间和城市的条件下，获取人物的类型")
    @PostMapping("getFigureTypesByTimeCity")
    public R getFigureTypesByTimeCity(@RequestBody TimeCityVo timeCityVo) {
        List<Map<String,Object>> figureTypes = figureService.getFigureTypesByTimeCity(timeCityVo);
        return R.ok().data("figureTypes",figureTypes);
    }

    @ApiOperation("获取年分的最小值和最大值")
    @GetMapping("getMinMaxYear")
    @Cacheable(value = "minMax",key = "'year'")
    public R getMinMaxYear() {
        Map<String, Object> minMaxYear = figureService.getMinMaxYear();
        return R.ok().data("minMaxYear",minMaxYear);
    }

    @ApiOperation("获取历史人物所有的经纬度")
    @GetMapping("getFigureLocAndLat")
    @Cacheable(value = "figure",key = "'LocAndLat'")
    public R getFigureLocAndLat() {
        List<Map<String, Object>> FigureLocAndLatList = figureService.getFigureLocAndLat();
        return R.ok().data("FigureLocAndLatList",FigureLocAndLatList);
    }

    @ApiOperation("获取历史人物类型的分类结果")
    @GetMapping("getFigureClassLocAndLat")
    @Cacheable(value = "figure",key = "'ClassLocAndLat'")
    public R getFigureClassLocAndLat() {
        Map<String, Object> FigureClassLocAndLatMap = figureService.getFigureClassLocAndLat();
        return R.ok().data("FigureClassLocAndLatMap",FigureClassLocAndLatMap);
    }
}
